package com.shy.web.page;

import java.io.Serializable;
import java.util.List;


/**
 * 前台分页信息
 * @author yinzhen
 */
public class PageView<T> implements Serializable {
	private static final long serialVersionUID = 1L;

	/** 分页数据 **/
	private List<T> records;
	/** 页码开始索引和结束索引 **/
	private PageIndex pageindex;
	/** 总页数 **/
	private Long totalpage = 1L;
	/** 每页显示记录数 **/
	private Long maxresult = PageConstants.PAGE_SIZE.longValue();
	/** 当前页 **/
	private Long currentpage = 1L;
	/** 总记录数 **/
	private Long totalrecord;
	/** 页码数量 **/
	private Long pagecode = PageConstants.PAGECODE_COUNT.longValue();
	
	/** 要获取记录的开始索引 **/
	public Long getFirstResult() {
		return (this.currentpage-1)*this.maxresult;
	}
	
	public List<T> getRecords() {
		return records;
	}
	public void setRecords(List<T> records) {
		this.records = records;
	}
	
	public PageIndex getPageindex() {
		return pageindex;
	}
	public void setPageindex(PageIndex pageindex) {
		this.pageindex = pageindex;
	}
	
	public long getTotalpage() {
		return totalpage;
	}
	public void setTotalpage(long totalpage) {
		this.totalpage = totalpage;
		this.pageindex = PageIndex.getPageIndex(pagecode,currentpage,totalpage);
	}
	
	public Long getMaxresult() {
		return maxresult;
	}
	public void setMaxresult(Long maxresult) {
		this.maxresult = maxresult;
	}
	
	public Long getCurrentpage() {
		return currentpage;
	}
	public void setCurrentpage(Long currentpage) {
		this.currentpage = currentpage;
	}
	
	public long getTotalrecord() {
		return totalrecord;
	}
	public void setTotalrecord(long totalrecord) {
		this.totalrecord = totalrecord;
		setTotalpage(this.totalrecord%this.maxresult==0?
				this.totalrecord/this.maxresult : this.totalrecord/this.maxresult+1);
	}
	
	public Long getPagecode() {
		return pagecode;
	}
	public void setPagecode(Long pagecode) {
		this.pagecode = pagecode;
	}
	
}
